const Mock = require('mockjs')

const List2 = []
const count2 = 100

for (let i = 0; i < count2; i++) {
  List2.push(Mock.mock({
    chip_id: '@increment',
    supplier: '@title(1, 3)',
    chip_no: +Mock.Random.date('T'),
    incoming_time: '2019-04-19 15:37:09.650',
    raycus_no: '@first',
    'status|1': ['停产', '待导入', '正常'],
    emitter_width: '@float(0, 100, 2, 2)',
    beam_divergence_parallel: '@float(0, 100, 2, 2)',
    module_type: '@first',
    mean_time_between_failure: '@float(0, 100, 2, 2)',
    standard_pulse_center_wavelength: '@float(0, 100, 2, 2)'
  }))
}

module.exports = [
  {
    url: '/chips/list',
    type: 'get',
    response: config => {
      const { type, title, page, limit, sort } = config.query
      // page=1&limit=20&supplier=&chipNo=&raycusNo=&emitterWidth=&moduleType=&wavelength=&sort=%2Bid
      let mockList = List2.filter(item => {
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 0,
        data: {
          total: mockList.length,
          page: Number(page),
          limit: Number(limit),
          items: pageList
        }
      }
    }
  }
]

